<?php
$eventTypeField = 'media_eventType_add_event';
$eventNameField = 'media_name_add_event';
$eventAliasField = 'media_alias_add_event';
$eventDescriptionField = 'media_description_add_event';
$eventTemplateField = 'media_template_add_event';
$model->addField($eventNameField);
$model->addField($eventAliasField);
$model->addField($eventDescriptionField);
$model->addField($eventTypeField);
$model->addField($eventTemplateField);

/*
  $app = Blyn::app()->getActiveApp();

  $operations = $app->getOperations();

  foreach ($operations as $op) {
  $opName = $op->getName();
  $opHomeField = 'media_' . $opName . 'Home' . '_add_event';
  $model->addField($opHomeField);
  }
 * 
 */


if ($eventId > 0) {
    $eventTable = new BAEventSheet();
    $event = $eventTable->getListById($eventId);
    $eventName = $event->getItem('name')->getValue();
    $model->$eventNameField = $eventName;

    $eventTypeId = $event->getItem('eventTypeId')->getValue();
    $model->$eventTypeField = $eventTypeId;
    
    $aliasItem = $event->getItem('alias');
    if ($aliasItem != NULL) {
        $model->$eventAliasField = $aliasItem->getValue();
    }

    $descriptionItem = $event->getItem('description');
    if ($descriptionItem != NULL) {
        $model->$eventDescriptionField = $descriptionItem->getValue();
    }

    $templateItem = $event->getItem('template');
    if ($templateItem != NULL) {
        $model->$eventTemplateField = $templateItem->getValue();
    }

    /*
      foreach ($operations as $op) {
      $opName = $op->getName();
      $eventOperationHomeName = $eventName.ucfirst($opName);
      $eventOperationHomeFileItem = $event->getItem($eventOperationHomeName);
      $opHomeField = 'media_' . $opName . 'Home' . '_add_event';
      if ($eventOperationHomeFileItem) {
      $model->$opHomeField = $eventOperationHomeFileItem->getValue();
      }
      }
     * 
     */
}
?>
<?php
$app = Blyn::app()->getActiveApp();
$cooker = new BAEventCooker();
//$typeList = $cooker->getEventTypeList('alias');
$typeList = Blyn::app()->getActiveApp()->getAppEventTypeListData();
$list = array('0' => '请选择');
$typeList = $list + $typeList;
?>

<table class="table table-hover">
    <colgroup>
        <col class="span1">
        <col class="span7">
    </colgroup>
    <thead>
        <tr>
            <th><?php echo '属性'; ?></th>
            <th><?php echo '内容'; ?></th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>
                <?php echo '功能类型'; ?>
            </td>
            <td>
                <?php
                echo $form->dropDownList($model, $eventTypeField, $typeList, array('class' => 'span7'));
                ?>
                <!--                    &nbsp;&nbsp;&nbsp;&nbsp;<a id="CreateNewType_clink" role="button" data-toggle="modal" class="btn disabled" style="font-size: 12px;margin-top: -12px;">创建新类型</a>-->
            </td>
        </tr>
        <tr><td> <?php echo '功能名称'; ?> </td>
            <td>
                <?php
                echo $form->textField($model, $eventNameField, array('placeholder' => '英文名称' . '...', 'required' => true));
                ?>
            </td>
        </tr>  
        <tr><td> <?php echo '功能别名'; ?> </td>
            <td>
                <?php
                echo $form->textField($model, $eventAliasField, array('placeholder' => '功能别名' . '...', 'required' => true));
                ?>
            </td>
        </tr>
        <tr>
            <td> <?php echo '功能简介'; ?>  </td>                    
            <td>
                <?php
                echo $form->textArea($model, $eventDescriptionField, array('placeholder' => '功能简介' . '...'));
                ?>
        </tr>
        <tr>
            <td> <?php echo '设置模版'; ?>  </td>                    
            <td>
                <?php
                echo $form->textField($model, $eventTemplateField, array('placeholder' => '设置模版' . '...'));
                ?>
        </tr>
        <?php
        /*
          foreach ($operations as $operation) {
          $opHomeField = 'media_' . $operation->getName() . 'Home' . '_add_event';
          ?>
          <tr>
          <td> <?php echo $operation->getName() . ' 首页'; ?>  </td>
          <td>
          <?php
          echo $form->textField($model, $opHomeField, array('placeholder' => '默认为：'.$operation->getName()));
          ?>
          </tr>
          <?php }
         */
        ?>
    </tbody>
</table>